//
//  LXLNavigationController.swift
//  Weibo-YQY-test
//
//  Created by Lang on 10/11/15.
//  Copyright © 2015 Lang. All rights reserved.
//

import UIKit

class LXLNavigationController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    }
    
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        print(childViewControllers.count)
        // 在这个地方判断如果当前 push 进来是第二个控制器的话，把它的返回按钮 title 设置为第一个控制器的 title
        if childViewControllers.count > 0 {
            var titleName = "返回"
            if childViewControllers.count == 1{
                titleName = childViewControllers.last!.title!
            }
            
            // 当 push 出来的时候，隐藏底部的 bar
            viewController.hidesBottomBarWhenPushed = true
            // 设置返回按钮
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.item("navigationbar_back_withtext", title: titleName, target: self, action: "back")
            
        }
        super.pushViewController(viewController, animated: true)
        
    }
    
    @objc private func back(){
        popViewControllerAnimated(true)
    }
    
}
